package fylder.chat;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;

import java.io.File;

import fylder.chat.tools.ChatPictrueTools;

/**
 * 聊天抽象
 * <p/>
 * 图片处理
 * Created by fylder on 2015/9/10.
 */
public abstract class ChatAbstract {

    Activity mContext;
    String PICTURE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/demo/temp";
    String path = PICTURE_PATH + "/picture.jpg";//临时文件
    String uriPath = "file://" + path;

    private Uri imageUri; // to store the big bitmap

    public ChatAbstract(Activity context) {
        this.mContext = context;
        File f = new File(PICTURE_PATH);
        if (!f.exists()) {
            f.mkdirs();
        }
        if (imageUri == null) {
            imageUri = Uri.parse(uriPath);
        }
    }

    /**
     * 发送信息
     */
    public abstract void sendMsg(String msg);

    /**
     * 发送图片
     */
    public abstract void sendImg();

    /**
     * 发送语音
     */
    public abstract void sendVoice();


    /**
     * 从图库获取图片
     */
    public void getPicture() {
        ChatPictrueTools.getPicture(mContext, imageUri);
    }

    /**
     * 拍照获取图片
     */
    public void getCamera() {
        ChatPictrueTools.getCammer(mContext, imageUri);
    }

    /**
     * 拍照回调的处理 ok
     */
    public void resultCamera() {
        //imageUri
        Log.w("123", "resultCamera");
    }

    /**
     * 图库回调的处理  KITKAT
     */
    public void resultPictureKit(Intent data) {
        //imageUri
        final Uri uri = data.getData();
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                ChatPictrueTools.resultPictureKit(uri, path, mContext);
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                //执行操作
            }
        }.execute();

    }

    /**
     * 图库回调的处理
     * <p/>
     * ?
     */
    public void resultPicture(Intent data) {
        //imageUri
        ChatPictrueTools.resultPicture(data, path, mContext);
    }
}
